﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Acme.BookStore2.Migrations
{
    public partial class vehicleattach : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_AttachFile_AppVehicleRepairRecord_OwnerId",
                table: "AttachFile");

            migrationBuilder.DropPrimaryKey(
                name: "PK_AttachFile",
                table: "AttachFile");

            migrationBuilder.DropColumn(
                name: "CreationTime",
                table: "AttachFile");

            migrationBuilder.RenameTable(
                name: "AttachFile",
                newName: "AppVehicleRepairRecord_AttachFiles");

            migrationBuilder.RenameIndex(
                name: "IX_AttachFile_OwnerId",
                table: "AppVehicleRepairRecord_AttachFiles",
                newName: "IX_AppVehicleRepairRecord_AttachFiles_OwnerId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_AppVehicleRepairRecord_AttachFiles",
                table: "AppVehicleRepairRecord_AttachFiles",
                column: "Id");

            migrationBuilder.CreateTable(
                name: "AppVehicle_AttachFiles",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    FileName = table.Column<string>(nullable: true),
                    BlobContainerName = table.Column<string>(nullable: true),
                    BlobName = table.Column<string>(nullable: true),
                    OwnerId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppVehicle_AttachFiles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppVehicle_AttachFiles_AppVehicle_OwnerId",
                        column: x => x.OwnerId,
                        principalTable: "AppVehicle",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AppVehicle_AttachFiles_OwnerId",
                table: "AppVehicle_AttachFiles",
                column: "OwnerId");

            migrationBuilder.AddForeignKey(
                name: "FK_AppVehicleRepairRecord_AttachFiles_AppVehicleRepairRecord_Ow~",
                table: "AppVehicleRepairRecord_AttachFiles",
                column: "OwnerId",
                principalTable: "AppVehicleRepairRecord",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_AppVehicleRepairRecord_AttachFiles_AppVehicleRepairRecord_Ow~",
                table: "AppVehicleRepairRecord_AttachFiles");

            migrationBuilder.DropTable(
                name: "AppVehicle_AttachFiles");

            migrationBuilder.DropPrimaryKey(
                name: "PK_AppVehicleRepairRecord_AttachFiles",
                table: "AppVehicleRepairRecord_AttachFiles");

            migrationBuilder.RenameTable(
                name: "AppVehicleRepairRecord_AttachFiles",
                newName: "AttachFile");

            migrationBuilder.RenameIndex(
                name: "IX_AppVehicleRepairRecord_AttachFiles_OwnerId",
                table: "AttachFile",
                newName: "IX_AttachFile_OwnerId");

            migrationBuilder.AddColumn<DateTime>(
                name: "CreationTime",
                table: "AttachFile",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddPrimaryKey(
                name: "PK_AttachFile",
                table: "AttachFile",
                column: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_AttachFile_AppVehicleRepairRecord_OwnerId",
                table: "AttachFile",
                column: "OwnerId",
                principalTable: "AppVehicleRepairRecord",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
